<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>业务移交</title>
<jsp:include page="../../import.jsp" flush="true" />
<style>
.inputCss{
-moz-border-radius:5px;
          -webkit-border-radius:5px;
          -ms-border-radius:5px;
          -khtml-border-radius:5px;
           border-radius:5px;
}
</style>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <table class="layout2col1">
        <tbody>
            <tr>
                <td width="50%" valign="top">
                    <div class="sqPanel">
                        <div class="sqPanel_head">
                            <span><i class="sqIco sqIco_3"></i>组织架构</span>
                        </div>
                        <br/>
                        <div class="sqPanel_body" style="min-height: 330px;">
                            <ul id="tree1">
                            </ul>
                        </div>
                    </div>
                </td>
                <td width="50%" valign="top">
                    <div class="sqPanel">
                        <div class="sqPanel_head">
                            <span><i class="sqIco sqIco_4"></i>项目经理</span>
                        </div>
                        <div class="sqPanel_body">
                        	<div class="btnsBox">
                        	<div style="width:60px;float:left">经理名称</div>
                			<div style="width:150px;float:left">
                				<input id="orgCd" value="" style="display:none">
                    			<input name="refRlNm" id="refRlNm" class="inputCss" type="text" value="">
                			</div>
                            	<span class="sq-button sq-button-round" style="float:left" id="search_btn">查询</span>
                                <span class="sq-button sq-button-hasicon" style="float:right;margin-right:25px" id="saveChange_btn"><i class="sqBtnIco_10"></i>保存</span>
                            </div>
                            <br/>
                            <div id="grid" class="sq-grid"></div>
                        </div>
                    </div>
                </td>
            </tr>
        </tbody>
    </table>
</div>

<script type="text/javascript">
	var grid = null;
	var tree;
	var ids = '${prjIds}';
	$(function () {
    tree = $("#tree1").ligerTree({
    	url: '<%=path%>/system/sysOrg/initList.do?orgTypCd=2',
        ajaxType: 'get',
        checkbox: false,
        parentIcon: "SqFolder",
        childIcon: "SqLeaf",
        needCancel:false,
        isExpand: false,
        onSelect: onSelectTree,
        onCancelselect: function (data,target) {
        }, 
        onSuccess: function (data) {
            tree.selectNode(data[0]);
        }
    });
    initGrid();
    function initGrid(){
    	$("#grid").ligerGrid({
        	url: '<%=path%>/project/prjbscinfo/showMgrListByOrgCd.do',
        	method : 'get',
            columns: [
                { display: '所属组织架构', name: 'orgCdNm', minWidth: 100 , enabledSort:true},
                { display: '经理名称', name: 'refRlNm', minWidth: 100 , enabledSort:true},
                { display: '登录名', name: 'usrNm', minWidth: 100 , enabledSort:true}
            ],
            pageSize:10,
            root:'rows',
            record:'total',
            hideLoadButton : true,
            width: '100%',
            height:'100%',
            heightDiff:-2,
            //isScroll: false,
            checkbox:true,
            delayLoad:true,
            rownumbers:true/* ,
            onRenderComplete: function () {
            	iframeResize ();
            } */
        });
      
        grid = liger.get("grid");
        grid.setHeight(100);
    }
    

    function onSelectTree (node) {
    	$("#orgCd").val(node.data.orgCd);
    	grid.setParm('orgCd',node.data.orgCd);
        grid.reload();
    }
    
    $("#search_btn").click(function(){
    	grid.setParm('refRlNm',$("#refRlNm").val());
    	grid.setParm('orgCd',$("#orgCd").val());
        grid.reload();
    }); 
  	//修改中的保存按钮
     $("#saveChange_btn").click(function(){
    	 
    	var selectedRows = grid.getSelectedRows();
 		if (selectedRows.length != 1) {
             $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
             return;
         }
 		var MgrId = "";
 		var refRlNm = "";
 		var orgCd = "";
 		for ( var index in selectedRows) {
 			MgrId = selectedRows[index].id;
 			refRlNm = selectedRows[index].refRlNm;
 			orgCd = selectedRows[index].orgCd;
 		}
  	    $.ajax({
  			type: 'post',
  			dataType:'json',
  			data:{
  				orgCd:orgCd,
  				refRlNm:refRlNm,
  				id:MgrId,
  				ids:ids
  			},
  			url: '<%=path%>/project/prjbscinfo/saveMgrListByOrgCd.do',
  			beforeSend: function(){
    	          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
    	     },
				success : function(msg) {
					if (msg.success == 1) {
						top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
						parent.grid.reload();
						parent.$.ligerDialog.close();
						parent.$(".l-dialog,.l-window-mask").css("display","none"); 
					} else {
						top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
					}
				}
			});
		});

		function setExpand2Parents(nodeid, treeid) {
			var tree = liger.get("tree1");
			var parent = tree.getParent(tree.getDataByID(nodeid));
			if (parent != null) {
				parent.isExpand = true;
				setExpand2Parents(parent.id);
			} else {
				tree.setData(tree.getData());
				console.log(tree.getData());
			}
			;
		}
	});
</script>
</body>
</html>